package com.kotlin.demo.ui

import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.foundation.layout.*
import androidx.compose.material.OutlinedButton
import androidx.compose.material.OutlinedTextField
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.kotlin.demo.helper.DialogHelper

/**
 * 编辑key 弹窗
 */
@Composable
@Preview
internal fun comEditDialog(key: String, title: String, sureText: String, back: (endKey: String) -> Unit) {
    var translateKey by remember { mutableStateOf(key) }//翻译res key
    Column(
        horizontalAlignment = Alignment.CenterHorizontally,
        modifier = Modifier.padding(start = 18.dp, end = 18.dp, top = 18.dp, bottom = 10.dp),
    ) {
        Text(
            text = title, style = TextStyle(fontSize = 14.sp), modifier = Modifier.padding(bottom = 10.dp)
        )
        OutlinedTextField(
            value = translateKey,
            onValueChange = { translateKey = it },
            placeholder = { Text("请确认翻译key", style = TextStyle(fontSize = 14.sp)) },
            textStyle = TextStyle(
                fontSize = 14.sp, lineHeight = TextUnit.Unspecified, color = Color.Black
            ),
            modifier = Modifier.width(280.dp).height(120.dp).padding(0.dp) // 使 TextField 填满其父组件的宽度
        )
        Row {
            OutlinedButton(
                onClick = {
                    back(translateKey.trim())
                },
                content = { Text(sureText, style = TextStyle(fontSize = 14.sp)) },
            )
            OutlinedButton(
                onClick = {
                    DialogHelper.dismissDialog()
                },
                content = { Text("取消", style = TextStyle(fontSize = 14.sp)) },
                modifier = Modifier.padding(start = 8.dp)
            )
        }
    }
}

